from itsdangerous import TimedJSONWebSignatureSerializer as Ser
from mei import settings
from apps.oauth.constants import OPENID_TOCKEN_EXPIRE_TIME

def generic_openid_tocken(openid):

    s = Ser(settings.SECRET_KEY, OPENID_TOCKEN_EXPIRE_TIME)
    data = {'openid':openid}
    tocken = s.dumps(data)
    tocken = tocken.decode()
    return tocken

from itsdangerous import BadData
import logging
logger = logging.getLogger('django')
def get_openid_token(token):
    s = Ser(settings.SECRET_KEY, OPENID_TOCKEN_EXPIRE_TIME)

    try:
        result = s.loads(token)
    except BadData as e:
        logger.error(e)
        return None
    return result.get('openid')


